package com.springdata.controller;

import com.springdata.pojo.CustInfo;
import com.springdata.service.CustInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author xwli
 * @date: 2021/10/5 15:38
 * @desc
 * @since JDK 1.8
 */

@RestController
@RequestMapping("/cust")
public class CustInfoContrlloer {


    @Autowired
    private CustInfoService custInfoService;

    @GetMapping("/get/no/{custNo}")
    public CustInfo getCustInfoByNo(@PathVariable("custNo") Long custNo){
        return custInfoService.getCustInfoByNo(custNo);
    }

    @GetMapping("/get/name/{custName}")
    public CustInfo getCustInfoByName(@PathVariable("custName") String custName){
        return custInfoService.getCustInfoByName(custName);
    }

    @GetMapping("/get/age/{custAge}")
    public CustInfo getCustInfoByAge(@PathVariable("custAge") String custAge){
        return custInfoService.getCustInfoByAge(custAge);
    }

    @GetMapping("/get/nameage")
    public CustInfo getCustInfoByNameAndAge(@RequestParam("name") String custName, @RequestParam("age") String custAge){
        return custInfoService.getCustInfoByNameAndAge(custName,custAge);
    }

    @GetMapping("/update/cust")
    public void updateCustInfo(@RequestParam("custno") Long custNo, @RequestParam("custname") String custName){
        custInfoService.updateCustInfo(custNo,custName);
    }

    @GetMapping("/find/no/{custNo}")
    public CustInfo findOneCustInfoByCustNo(@PathVariable("custNo") Long custNo){
        return custInfoService.findOneCustInfoByCustNo(custNo);
    }

    @GetMapping("/find/idAndname")
    public CustInfo findOneCustInfoByCustNoAndCustName(@RequestParam("custno") Long custNo, @RequestParam("custname") String custName){
        return custInfoService.findOneCustInfoByCustNoAndCustName(custNo,custName);
    }

    @GetMapping("/find/name")
    public List<CustInfo> findAllCustInfoLikeCustName(@RequestParam("custname") String custName){
        return custInfoService.findAllCustInfoLikeCustName(custName);
    }
}

